//
//  WBTitleButton.swift
//  SinaWeibo
//
//  Created by 美食家 on 17/4/12.
//  Copyright © 2017年 不孤独的美食家. All rights reserved.
//

import UIKit

class WBTitleButton: UIButton {

    init(title:String?) {
        super.init(frame: CGRect())
        
        if title == nil {
            setTitle("首页", for: [])
        }else{
            setTitle(title!, for: [])
            setImage(UIImage(named:"navigationbar_arrow_down"), for: [])
            setImage(UIImage(named:"navigationbar_arrow_up"), for: .selected)
        }
        
        titleLabel?.font=UIFont.boldSystemFont(ofSize: 15)
        setTitleColor(UIColor.red, for: [])
        sizeToFit()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        guard let titleLabel=titleLabel,let imageView=imageView else {
            return
        }
        
        titleLabel.frame=titleLabel.frame.offsetBy(dx: -imageView.frame.width, dy: 0)
//        titleLabel.backgroundColor=UIColor.green
        imageView.frame=imageView.frame.offsetBy(dx:titleLabel.frame.width*0.5-3, dy: 0)
//        imageView.backgroundColor=UIColor.blue
        
//        print("\(titleLabel),\(imageView)")
    }
    
    
}
